package org.xqyy.eval.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xqyy.eval.dao.TSystemCycleMapper;
import org.xqyy.eval.model.TSystemCycle;
import org.xqyy.eval.service.ISystemCycleService;
import tk.mybatis.mapper.entity.Example;
import java.util.Date;
import java.util.List;

@Service
public class SystemCycleService implements ISystemCycleService {

    @Autowired
    private TSystemCycleMapper systemCycleMapper;
    /**
     * 返回系统填报周期时间段
     *
     * @return
     */
    @Override
    public Date[] findCycleInfo() {

        return new Date[0];
    }

    /**
     * 添加系统填报周期
     *
     * @param systemCycle
     * @return
     */
    @Override
    public Boolean addSystemCycle(TSystemCycle systemCycle) {
        systemCycleMapper.insert(systemCycle);
        return true;
    }

    /**
     * 查询系统填报周期
     *
     * @param id@return
     */
    @Override
    public TSystemCycle findSystemCycleById(Integer id) {
        return systemCycleMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询系统填报周期数据
     *
     * @return
     */
    @Override
    public List<TSystemCycle> selectSystemCycle() {
        Example example = new Example(TSystemCycle.class);
        example.setOrderByClause("begindate desc");
        return systemCycleMapper.selectByExample(example);
    }

    /**
     * 修改系统填报周期数据
     *
     * @param systemCycle
     * @return
     */
    @Override
    public Boolean updateSystemCycle(TSystemCycle systemCycle) {
        systemCycleMapper.updateByPrimaryKey(systemCycle);
        return true;
    }

    /**
     * 删除系统填报周期数据
     *
     * @param systemCycle
     * @return
     */
    @Override
    public Boolean delSystemCycle(TSystemCycle systemCycle) {
        systemCycleMapper.deleteByPrimaryKey(systemCycle);
        return true;
    }

    /**
     * 获取当前时间需要填报的期数
     *
     * @return
     */
    @Override
    public TSystemCycle selectNowDate() {
        List<TSystemCycle> systemCycleList = systemCycleMapper.selectNowDate();
        if (systemCycleList.size() > 0 ){
            return  systemCycleList.get(0);
        }
        return null;
    }

    /**
     * 判断当前时间是否存在上报的期数
     *
     * @return
     */
    @Override
    public Boolean nowIsPresenceCycle() {
        List<TSystemCycle> systemCycleList = systemCycleMapper.selectNowDate();
        return systemCycleList.size()>0?true:false;
    }


}
